package com.github.soiff.shadow.plugin.helper;

import com.github.jknack.handlebars.Helper;
import com.github.jknack.handlebars.Options;
import com.github.soiff.shadow.plugin.utils.JsonMapper;

import java.io.IOException;
import java.util.Map;

/**
 * Created by Soiff on 2016/05/20.
 *
 * @author : Soiff
 */
public class MappingHelper implements Helper {
    @Override
    public CharSequence apply(Object param, Options options) throws IOException {
        CharSequence mappingJson = options.fn();
        Map mappingMap = JsonMapper.nonEmptyMapper().fromJson(String.valueOf(mappingJson), Map.class);
        return String.valueOf(mappingMap.get(param.toString()));
    }
}
